package com.zoujt.listeners;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/*
 * @auth zoujt
 * @date 2021/2/27
 * @Description
 */
@WebListener
public class SessionListener implements HttpSessionListener {
    int count = 0;
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        count++;
        ServletContext application = se.getSession().getServletContext();
        application.setAttribute("countNum",count);
        System.out.println("我进去了");
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        count--;
        ServletContext application = se.getSession().getServletContext();
        application.setAttribute("countNum",count);
        System.out.println("我出来了");
    }
}
